<template>
    <div>
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>部门管理</el-breadcrumb-item>
            <el-breadcrumb-item>新增部门</el-breadcrumb-item>
        </el-breadcrumb>
        <el-divider></el-divider>
        <el-form  :model="form" ref="form" :rules="rules" label-width="80px" style="width:500px;" >
            <el-form-item label="部门名称" prop="deptName">
                <el-input   v-model="form.deptName" placeholder="请输入部门名称"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button @click="addDept" type="primary" round>新增</el-button>
                <el-button @click="resetForm" type="success" round>取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                form: {
                    deptName:'',
                },
                rules:{
                    deptName:[{required:true,message:'部门地址必填',trigger:'blur'}],
                }
            }
        },
        methods:{
            addDept(){
                this.$refs['form'].validate(valid=>{
                    if(valid){
                        //console.log(this.form);
                        this.$http.deptApi.add(this.form).then(res=>{
                        console.log(res);
                        if(res.data.code==200){
                            this.$message({
                                type:'success',
                                message:'增加部门成功'
                            })
                            this.$router.push('/home/dept-list')
                        }
                        }).catch(err=>console.log(err))
                    }else{
                        this.$notify({
                            type:'error',
                            message:'表单填写错误！'
                        })
                    }
                })
            },
            resetForm(){
                this.$refs.form.resetFields();
            }
        }
    }
</script>

<style lang="scss" scoped>

</style>